package com.huike.web.controller.report;


import com.huike.report.domain.vo.BusinessChangeStatisticsVO;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import net.sf.cglib.core.Local;
import org.apache.poi.ss.formula.functions.Today;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {

        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo() {
        LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime todayEnd=LocalDateTime.of(LocalDate.now(),LocalTime.MAX);
        DateTimeFormatter timeFormatter= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String startTime = timeFormatter.format(todayStart);
        String endTime = timeFormatter.format(todayEnd);
        System.out.println(startTime);
        System.out.println(endTime);
        IndexTodayInfoVO indexTodayInfoVO=reportService.getTodayInfo(startTime,endTime);

        return AjaxResult.success(indexTodayInfoVO);
    }

    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){

       IndexTodoInfoVO indexTodoInfoVO= reportService.getTodoInfo(beginCreateTime, endCreateTime);
        return AjaxResult.success(indexTodoInfoVO);
    }

    @GetMapping("/businessChangeStatistics")
    public AjaxResult getBusinessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                                  @RequestParam("endCreateTime") String endCreateTime){

        List<Map<String,Object>> statisticsList=reportService.getBusinessChangeStatistics(beginCreateTime,endCreateTime);

        return AjaxResult.success(statisticsList);
    }

    @GetMapping("/salesStatistic")
    public AjaxResult getSalesStatistic(@RequestParam("beginCreateTime") String beginCreateTime,
                                        @RequestParam("endCreateTime") String endCreateTime){


        List<Map<String,Object>> statisticsList = reportService.getChangeSalesStatistic(beginCreateTime,endCreateTime);

        return AjaxResult.success(statisticsList);
    }


}